home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / rayshade / libshade / yacc.y < prev   
Text File  |  1994-08-01  |  30KB  |  1,488 lines

  1. /* yacc.y                                   */
  2. /*                                       */
  3. /* Copyright (C) 1989, 1991, Craig E. Kolb                   */
  4. /* All rights reserved.                               */
  5. /*                                       */
  6. /* This software may be freely copied, modified, and redistributed,       */
  7. /* provided that this copyright notice is preserved on all copies.       */
  8. /*                                       */
  9. /* You may not distribute this software, in whole or in part, as part of   */
  10. /* any commercial product without the express consent of the authors.       */
  11. /*                                        */
  12. /* There is no warranty or other guarantee of fitness of this software       */
  13. /* for any purpose.  It is provided solely "as is".               */
  14. /* $Id: yacc.y,v 4.0.1.4 92/01/10 16:29:55 cek Exp Locker: cek $ */
  15. %{
  16. #include "rayshade.h"
  17.  
  18. #include "symtab.h"
  19. #include "builtin.h"
  20.  
  21. #include "libsurf/atmosphere.h"
  22. #include "libsurf/surface.h"
  23. #include "libtext/texture.h"
  24. #include "libimage/image.h"
  25. #include "libobj/geom.h"
  26. #include "liblight/light.h"
  27. #include "options.h"
  28. #include "stats.h"
  29. #include "viewing.h"
  30.  
  31. #include "libobj/blob.h"
  32. #include "libobj/box.h"
  33. #include "libobj/cone.h"
  34. #include "libobj/csg.h"
  35. #include "libobj/cylinder.h"
  36. #include "libobj/disc.h"
  37. #include "libobj/grid.h"
  38. #include "libobj/hf.h"
  39. #include "libobj/instance.h"
  40. #include "libobj/list.h"
  41. #include "libobj/plane.h"
  42. #include "libobj/poly.h"
  43. #include "libobj/sphere.h"
  44. #include "libobj/torus.h"
  45. #include "libobj/triangle.h"
  46.  
  47. #include "liblight/point.h"
  48. #include "liblight/infinite.h"
  49. #include "liblight/spot.h"
  50. #include "liblight/jittered.h"
  51. #include "liblight/extended.h"
  52.  
  53. #include "libtext/blotch.h"
  54. #include "libtext/bump.h"
  55. #include "libtext/checker.h"
  56. #include "libtext/cloud.h"
  57. #include "libtext/fbm.h"
  58. #include "libtext/fbmbump.h"
  59. #include "libtext/gloss.h"
  60. #include "libtext/imagetext.h"
  61. #include "libtext/marble.h"
  62. #include "libtext/mount.h"
  63. #include "libtext/sky.h"
  64. #include "libtext/stripe.h"
  65. #include "libtext/windy.h"
  66. #include "libtext/wood.h"
  67.  
  68. #include "libsurf/fog.h"
  69. #include "libsurf/fogdeck.h"
  70. #include "libsurf/mist.h"
  71.  
  72. #include "libcommon/rotate.h"
  73. #include "libcommon/scale.h"
  74. #include "libcommon/translate.h"
  75. #include "libcommon/xform.h"
  76.  
  77. Geom *NewAggregate();
  78. char yyfilename[BUFSIZ];            /* Input filename */
  79. GeomList *Defstack;                /* Geom definition stack. */
  80. int Npoints = 0;                /* # of points in Polypoints */
  81. Surface *tmpsurf;                /* Working surface */
  82. SurfList *CurSurf;
  83. Texture *CurText;                /* Working list of textures */
  84. ImageText *Imagetext;                /* Working image texture */
  85. Trans *TransHead, *TransTail;            /* Linked list of current transformations */
  86. Atmosphere *CurEffect = (Atmosphere *)NULL;    /* Current atmos. effects */ 
  87. PointList *Polypoints;                /* List of vertices */
  88. MetaList *Metapoints, *Metapoint;
  89. extern FILE *yyin;                /* input file pointer */
  90. extern int yylineno;                /* Current line # in file */
  91. extern Atmosphere *AtmosEffects;        /* atmospheric effects */
  92. extern Medium TopMedium;            /* "air" */
  93. extern void    GeomAddToDefined(),
  94.         LightAddToDefined(),
  95.         SurfaceAddToDefined();
  96. extern Surface    *SurfaceGetNamed();
  97. extern Geom     *GeomGetNamed();
  98. %}
  99. %union {
  100.     char *c;
  101.     int i;
  102.     Float d;
  103.     Vector v;
  104.     Vec2d uv;
  105.     Color col;
  106.     Atmosphere *atmos;
  107.     Light *light;
  108.     Surface *surf;
  109.     Geom *obj;
  110.     Texture *text;
  111.     Mapping *map;
  112.     Trans *trans;
  113.     Expr *e;
  114.     SymtabEntry *sym;
  115. }
  116. %token <d> tFLOAT
  117. %token <c> tSTRING tFILENAME
  118. %token tAPERTURE tAPPLYSURF
  119. %token tBACKGROUND tBLOB tBLOTCH tBOX tBUMP tCONE tCYL tDIRECTIONAL tCURSURF
  120. %token tEXTENDED tEYEP tFBM tFBMBUMP tFOCALDIST tFOG tFOGDECK tFOV tGLOSS tGRID
  121. %token tHEIGHTFIELD tLIGHT tLIST tLOOKP tMARBLE tMAXDEPTH tMIST
  122. %token tJITTER tNOJITTER tDEFINE
  123. %token tOBJECT tOUTFILE  tSKY tDISC tDIFFERENCE tUNION tINTERSECT
  124. %token tPLANE tPOINT tPOLY tROTATE tSPOT tPRINT
  125. %token tSCALE tSCREEN tSPHERE tSURFACE
  126. %token tTHRESH tTRANSLATE tTRANSFORM tTRIANGLE tTRIANGLEUV tUP tEND
  127. %token tTEXTURE tCHECKER tWOOD tCONTRAST tCUTOFF tCLOUD
  128. %token tAMBIENT tDIFFUSE tREFLECT tTRANSP tSPECULAR tSPECPOW
  129. %token tINDEX tATMOSPHERE tNOSHADOW tAREA tTRANSLU tTORUS
  130. %token tEYESEP tSHADOWTRANSP tREPORT tVERBOSE tQUIET tWINDOW tCROP tSTRIPE
  131. %token tMAP tUV tSPHERICAL tCYLINDRICAL tPLANAR
  132. %token tIMAGE tSMOOTH tCOMPONENT tTEXTSURF tRANGE tTILE tSTARTTIME tFRAMELENGTH
  133. %token tNAME tFILTER tGAUSS tBODY tSAMPLE tEXTINCT tWINDY tMOUNT
  134. %token tSHUTTER tFRAMES
  135. %type <c> Filename
  136. %type <e> AnimExpr MExpr ParenExpr
  137. %type <d> Expr Float
  138. %type <v> Vector
  139. %type <uv> Vec2d
  140. %type <col> Color Intensity Lightdef
  141. %type <text> Texturetype
  142. %type <i> SurfCompName IExpr CombineOp
  143. %type <atmos> EffectType
  144. %type <light> LightType
  145. %type <obj> PrimType Primitive TransTextObj
  146. %type <obj> Csg Aggregate Object TransObj ObjType
  147. %type <obj> Blob Box Cone Cylinder Disc HeightField Plane Poly
  148. %type <obj> Sphere Triangle Torus AggregateType List Grid AggregateCreate
  149. %type <obj> NamedObject
  150. %type <surf> Surface OptSurface NamedSurf
  151. %type <surf> SurfSpec ModifyNamedSurf
  152. %type <map> Mapping MapMethod OptMapping
  153. %type <trans> TransformType
  154. %type <sym> Symtabent
  155.  
  156. %left '+' '-'
  157. %left '*' '/' '%'
  158. %left UMINUS
  159. %right '^'
  160. %%
  161. Items        : /* empty */
  162.         | Items Item
  163.         ;
  164. Item        : Eyep
  165.         | Lookp
  166.         | Up
  167.         | Fov
  168.         | Screen
  169.         | Window
  170.         | Crop
  171.         | Report
  172.         | Aperture
  173.         | Focaldist
  174.         | Eyesep
  175.         | Maxdepth
  176.         | Sample
  177.         | Filter
  178.         | Contrast
  179.         | Cutoff
  180.         | Background
  181.         | Shadowtransp
  182.         | Light
  183.         | SurfDef
  184.         | CurSurf
  185.         | Outfile
  186.         | Instance
  187.         | NameObject
  188.         | GlobalEffects
  189.         | Define
  190.         | Frames
  191.         | Starttime
  192.         | Shutter
  193.         | Framelength
  194.             | Print
  195.         ;
  196. Instance    : TransTextObj
  197.         {
  198.             if ($1) {
  199.                 /*
  200.                  * Add instance to current object.
  201.                  */
  202.                 $1->next = Defstack->obj->next;
  203.                 Defstack->obj->next = $1;
  204.             }
  205.         }
  206. TransTextObj    : TransObj Textures
  207.         {
  208.             if ($$ && CurText) {
  209.                 $$->texture = TextAppend(CurText, $$->texture);
  210.             }
  211.             CurText = (Texture *)NULL;
  212.         }
  213.         ;    
  214. TransObj    : Object Transforms
  215.         {
  216.             $$ = $1;
  217.             if ($$ != (Geom *)NULL) {
  218.                 if (TransHead) {
  219.                     $$->trans = TransHead;
  220.                     $$->transtail = TransTail;
  221.                     /*
  222.                      * We compose non-animated tranformation lists,
  223.                      * so we're only animated if it's one long,
  224.                      * or it's animated itself.
  225.                      */
  226.                     if ($$->trans->assoc || $$->trans->next)
  227.                         /* geometry is animated...*/
  228.                         $$->animtrans = TRUE;
  229.                 }
  230.             }
  231.         }
  232.         ;
  233. Object        : ObjType
  234.         {
  235.             if ($$)
  236.                 StatsAddRep($$);
  237.         }
  238.         | NamedObject
  239.         ;
  240. ObjType        : Primitive
  241.         | Aggregate
  242.         ;
  243. Primitive    : PrimType
  244.         {
  245.             if ($$)
  246.                 $$->prims = 1;    /* one primitive */
  247.         }
  248.         ;
  249. PrimType    : Plane
  250.         | Sphere
  251.         | Box
  252.         | Triangle
  253.         | Cylinder
  254.         | Cone
  255.         | Poly
  256.         | HeightField
  257.         | Disc
  258.         | Torus
  259.         | Blob
  260.         ;
  261. NameObject    : tNAME tSTRING TransTextObj
  262.         {
  263.             if ($3) {
  264.                 $3->name = $2;
  265.                 GeomAddToDefined($3);
  266.             }
  267.         };
  268. Aggdefs        : Aggdefs Aggdef
  269.         |
  270.         ;
  271. Aggdef        : Instance
  272.         | SurfDef
  273.         | CurSurf
  274.         | NameObject
  275.         ;
  276. Textures    : Textures Texture
  277.         |
  278.         ;
  279. Texture        : tTEXTURE Texturetype Transforms
  280.         {
  281.             if ($2 != (Texture *)NULL) {
  282.                 /*
  283.                  * Set transformation information.
  284.                  */
  285.                 if (TransHead) {
  286.                     $2->trans = TransHead;
  287.                     /*
  288.                      * We compose non-animated tranformation lists,
  289.                      * so we're only animated if it's one long,
  290.                      * or it's animated itself.
  291.                      */
  292.                     if ($2->trans->assoc || $2->trans->next)
  293.                         /* texture transformation is animated...*/
  294.                         $2->animtrans = TRUE;
  295.                 }
  296.                 /*
  297.                  * Walk to the end of list of textures and
  298.                  * append new texture.  This is done so that
  299.                  * textures are applied in the expected order.
  300.                  */
  301.                 CurText = TextAppend($2, CurText);
  302.             }
  303.         }
  304.         ;
  305. Texturetype    : tCHECKER Surface
  306.         {
  307.             $$ = TextCheckerCreate($2);
  308.         }
  309.         | tBLOTCH Expr Surface
  310.         {
  311.             $$ = TextBlotchCreate($2, $3);
  312.         }
  313.         | tBUMP Expr
  314.         {
  315.             $$ = TextBumpCreate($2);
  316.         }
  317.         | tMARBLE
  318.         {
  319.             $$ = TextMarbleCreate((char *)NULL);
  320.         }
  321.         | tMARBLE Filename
  322.         {
  323.             $$ = TextMarbleCreate($2);
  324.         }
  325.         | tFBM Expr Expr Expr Expr IExpr Expr
  326.         {
  327.             $$ = TextFBmCreate($2, $3, $4, $5, $6, $7,
  328.                         (char *)NULL);
  329.         }
  330.         | tFBM Expr Expr Expr Expr IExpr Expr Filename
  331.         {
  332.             $$ = TextFBmCreate($2, $3, $4, $5, $6, $7, $8);
  333.         }
  334.         | tFBMBUMP Expr Expr Expr Expr IExpr 
  335.         {
  336.             $$ = TextFBmBumpCreate($2, $3, $4, $5, $6);
  337.         }
  338.         | tWOOD
  339.         {
  340.             $$ = TextWoodCreate();
  341.         }
  342.         | tGLOSS Expr 
  343.         {
  344.             $$ = TextGlossCreate($2);
  345.         }
  346.         | tCLOUD Expr Expr Expr IExpr Expr Expr Expr
  347.         {
  348.             $$ = TextCloudCreate($2, $3, $4, $5, $6, $7, $8);
  349.         }
  350.         | tSKY Expr Expr Expr IExpr Expr Expr
  351.         {
  352.             $$ = TextSkyCreate($2, $3, $4, $5, $6, $7);
  353.         }
  354.         | ImageText
  355.         {
  356.             /*
  357.              * Image texturing has so many options
  358.              * that specification is keyword-based.
  359.              */
  360.             if (Imagetext->image == (Image *)NULL)
  361.                 $$ = (Texture *)NULL;
  362.             else
  363.                 $$ = TextCreate(Imagetext, ImageTextApply);
  364.             Imagetext = (ImageText *)NULL;
  365.         }
  366.         | tSTRIPE Surface Expr Expr OptMapping
  367.         {
  368.             $$ = TextStripeCreate($2, $3, $4, $5);
  369.         }
  370.         | tWINDY Expr Expr Expr Expr IExpr Expr Expr Expr
  371.         {
  372.             $$ = TextWindyCreate($2, $3, $4, $5, $6, $7, $8, $9);
  373.         }
  374.         | tMOUNT Filename Expr Expr
  375.         {
  376.             $$ = TextMountCreate($2, $3, $4);
  377.         }
  378.         ;
  379. ImageText    : ImageTextType ImageTextOptions
  380.         ;
  381. ImageTextType    : tIMAGE Filename
  382.         {
  383.             Imagetext = ImageTextCreate($2);
  384.         }
  385.         ;
  386. ImageTextOptions: ImageTextOptions ImageTextOption
  387.         | /* EMPTY */
  388.         ;
  389. ImageTextOption: tCOMPONENT SurfCompName
  390.         {
  391.             /* set texture to modify given component */    
  392.             ImageTextSetComponent(Imagetext, $2);
  393.         }
  394.         | tTILE Expr Expr
  395.         {
  396.             Imagetext->tileu = $2;
  397.             Imagetext->tilev = $3;
  398.         }
  399.         | tTEXTSURF Surface
  400.         {
  401.             Imagetext->surf = $2;
  402.         }
  403.         | tRANGE Expr Expr
  404.         {
  405.             Imagetext->hi = $2;
  406.             Imagetext->lo = $3;
  407.         }
  408.         | tSMOOTH
  409.         {
  410.             Imagetext->smooth = TRUE;
  411.         }
  412.         | Mapping
  413.         {
  414.             Imagetext->mapping = $1;
  415.         };
  416. NamedObject    : tOBJECT Surface tSTRING
  417.         {
  418.             Geom *otmp;
  419.             /*
  420.              * Create an instance of the named object.
  421.              */
  422.             otmp = GeomGetNamed($3);
  423.             if (otmp == (Geom *)NULL)
  424.                 RLerror(RL_PANIC,
  425.                   "There is no object named \"%s\".", $3);
  426.             $$ = GeomInstanceCreate(otmp);
  427.             $$->surf = $2;
  428.             $$->prims = otmp->prims;
  429.         }
  430.         | tOBJECT tSTRING
  431.         {
  432.             Geom *otmp;
  433.  
  434.             otmp = GeomGetNamed($2);
  435.             if (otmp == (Geom *)NULL)
  436.                 RLerror(RL_PANIC,
  437.                   "There is no object named \"%s\".", $2);
  438.             $$ = GeomInstanceCreate(otmp);
  439.             $$->surf = CurSurf->surf;
  440.             $$->prims = otmp->prims;
  441.         };
  442. Transforms    : Transforms PostTransform
  443.         | /* empty */
  444.         {
  445.             TransHead = TransTail = (Trans *)NULL;
  446.         };
  447. PostTransform    : TransformType
  448.         {
  449.             if (TransHead == (Trans *)NULL) {
  450.                 /* we're the list, head and tail */
  451.                 TransHead = TransTail = $1;
  452.             } else {
  453.                 if ($1->animated || TransTail->animated) {
  454.                     /* new tail */
  455.                     $1->prev = TransTail;
  456.                     TransTail->next = $1;
  457.                     TransTail = $1;
  458.                 } else {
  459.                     /* collapse with tail */
  460.                     TransCompose(TransTail, $1, TransTail);
  461.                     TransFree($1);
  462.                 }
  463.             }
  464.         }
  465.         ;
  466. TransformType    : tSCALE AnimExpr AnimExpr AnimExpr
  467.         {
  468.             $$ = TransScaleCreate();
  469.             TransScaleSetX($$, $2);
  470.             TransScaleSetY($$, $3);
  471.             TransScaleSetZ($$, $4);
  472.             if (!$$->animated)
  473.                 TransPropagate($$);
  474.                 
  475.         }
  476.         | tTRANSLATE AnimExpr AnimExpr AnimExpr
  477.         {
  478.             $$ = TransTranslateCreate();
  479.             TransTranslateSetX($$, $2);
  480.             TransTranslateSetY($$, $3);
  481.             TransTranslateSetZ($$, $4);
  482.             if (!$$->animated)
  483.                 TransPropagate($$);
  484.         }
  485.         | tROTATE AnimExpr AnimExpr AnimExpr AnimExpr
  486.         {
  487.             $$ = TransRotateCreate();
  488.             TransRotateSetX($$, $2);
  489.             TransRotateSetY($$, $3);
  490.             TransRotateSetZ($$, $4);
  491.             TransRotateSetTheta($$, $5);
  492.             if (!$$->animated)
  493.                 TransPropagate($$);
  494.         }
  495.         | tTRANSFORM    AnimExpr AnimExpr AnimExpr
  496.                 AnimExpr AnimExpr AnimExpr
  497.                 AnimExpr AnimExpr AnimExpr
  498.         {
  499.             $$ = TransXformCreate();
  500.             TransXformSetX0($$, $2);
  501.             TransXformSetY0($$, $3);
  502.             TransXformSetZ0($$, $4);
  503.             TransXformSetX1($$, $5);
  504.             TransXformSetY1($$, $6);
  505.             TransXformSetZ1($$, $7);
  506.             TransXformSetX2($$, $8);
  507.             TransXformSetY2($$, $9);
  508.             TransXformSetZ2($$, $10);
  509.             if (!$$->animated)
  510.                 TransPropagate($$);
  511.         }
  512.         | tTRANSFORM    AnimExpr AnimExpr AnimExpr
  513.                 AnimExpr AnimExpr AnimExpr
  514.                 AnimExpr AnimExpr AnimExpr
  515.                 AnimExpr AnimExpr AnimExpr
  516.         {
  517.             $$ = TransXformCreate();
  518.             TransXformSetX0($$, $2);
  519.             TransXformSetY0($$, $3);
  520.             TransXformSetZ0($$, $4);
  521.             TransXformSetX1($$, $5);
  522.             TransXformSetY1($$, $6);
  523.             TransXformSetZ1($$, $7);
  524.             TransXformSetX2($$, $8);
  525.             TransXformSetY2($$, $9);
  526.             TransXformSetZ2($$, $10);
  527.             TransXformSetXt($$, $11);
  528.             TransXformSetYt($$, $12);
  529.             TransXformSetZt($$, $13);
  530.             if (!$$->animated)
  531.                 TransPropagate($$);
  532.         };
  533. Eyep        : tEYEP Vector Transforms
  534.         {
  535.             Camera.pos = $2;
  536.             /*
  537.              * Eye can be transformed...
  538.             if (CurMatrix) {
  539.                 PointTransform(&Camera.pos, CurMatrix);
  540.                 free((voidstar)CurMatrix);
  541.                 CurMatrix = (Matrix*)NULL;
  542.             }
  543.              */
  544.         }
  545.         ;
  546. Lookp        : tLOOKP Vector
  547.         {
  548.             Camera.lookp = $2;
  549.         }
  550.         ;
  551. Up        : tUP Vector
  552.         {
  553.             Camera.up = $2;
  554.         }
  555.         ;
  556. Fov        : tFOV Expr Expr
  557.         {
  558.             Camera.hfov = $2;
  559.             Camera.vfov = $3;
  560.         }
  561.         | tFOV Expr
  562.         {
  563.             Camera.hfov = $2;
  564.             Camera.vfov = UNSET;
  565.         }
  566.         ;
  567. Sample        : tSAMPLE IExpr tJITTER
  568.         {
  569.             if (!Options.samples_set)
  570.                 Options.samples = $2;
  571.             if (!Options.jitter_set)
  572.                 Options.jitter = TRUE;
  573.         }
  574.         | tSAMPLE IExpr tNOJITTER
  575.         {
  576.             if (!Options.samples_set)
  577.                 Options.samples = $2;
  578.             if (!Options.jitter_set)
  579.                 Options.jitter = FALSE;
  580.         }
  581.         | tSAMPLE IExpr
  582.         {
  583.             if (!Options.samples_set)
  584.                 Options.samples = $2;
  585.         }
  586.         ;
  587. Filter        : tFILTER tBOX Expr
  588.         {
  589.             Options.gaussian = FALSE;
  590.             Options.filterwidth = $3;
  591.         }
  592.         | tFILTER tBOX
  593.         {
  594.             Options.gaussian = FALSE;
  595.         }    
  596.         | tFILTER tGAUSS Expr
  597.         {
  598.             Options.gaussian = TRUE;
  599.             Options.filterwidth = $3;
  600.         }
  601.         | tFILTER tGAUSS
  602.         {
  603.             Options.gaussian = TRUE;
  604.         };
  605. Starttime    : tSTARTTIME Expr
  606.         {
  607.             Options.starttime = $2;
  608.         };
  609. Frames        : tFRAMES IExpr
  610.         {
  611.             if (!Options.totalframes_set)
  612.                 Options.totalframes = $2;
  613.         };
  614. Framelength    : tFRAMELENGTH Expr
  615.         {
  616.             Options.framelength = $2;
  617.         };
  618. Shutter        : tSHUTTER Expr
  619.         {
  620.             Options.shutterspeed = $2;
  621.         };
  622. Contrast    : tCONTRAST Expr Expr Expr
  623.         {
  624.             if (!Options.contrast_set) {
  625.                 Options.contrast.r = $2;
  626.                 Options.contrast.g = $3;
  627.                 Options.contrast.b = $4;
  628.             }
  629.         }
  630.         ;
  631. Cutoff        : tCUTOFF Intensity
  632.         {
  633.             if (!Options.cutoff_set)
  634.                 Options.cutoff = $2;
  635.         }
  636.         ;
  637. Screen        : tSCREEN IExpr IExpr 
  638.         {
  639.             if (!Options.resolution_set) {
  640.                 Screen.xres = $2;
  641.                 Screen.yres = $3;
  642.             }
  643.         }
  644.         ;
  645. Window        : tWINDOW IExpr IExpr IExpr IExpr
  646.         {
  647.             if (!Options.window_set) {
  648.                 Options.window[LOW][X] = $2;
  649.                 Options.window[HIGH][X] = $3;
  650.                 Options.window[LOW][Y] = $4;
  651.                 Options.window[HIGH][Y] = $5;
  652.                 /*
  653.                  * We must let ViewingSetup know
  654.                  * that a window has been defined.
  655.                  */
  656.                 Options.window_set = TRUE;
  657.             }
  658.         }
  659.         ;
  660. Crop        : tCROP Expr Expr Expr Expr
  661.         {
  662.             if (!Options.crop_set) {
  663.                 Options.crop[LOW][X] = $2;
  664.                 Options.crop[HIGH][X] = $3;
  665.                 Options.crop[LOW][Y] = $4;
  666.                 Options.crop[HIGH][Y] = $5;
  667.             }
  668.         }
  669.         ;
  670. Report        : tREPORT Verbose Quiet IExpr Filename
  671.         {
  672.             if (!Options.freq_set)
  673.                 Options.report_freq = $4;
  674.             if (Options.statsname == (char *)NULL)
  675.                 Options.statsname = strsave($5);
  676.         }
  677.         | tREPORT Verbose Quiet IExpr
  678.         {
  679.             if (!Options.freq_set)
  680.                 Options.report_freq = $4;
  681.         }
  682.         | tREPORT Verbose Quiet Filename
  683.         {
  684.             if (Options.statsname == (char *)NULL)
  685.                 Options.statsname = strsave($4);
  686.         }
  687.         | tREPORT Verbose Quiet
  688.         ;
  689. Verbose        : tVERBOSE
  690.         { Options.verbose = TRUE; }
  691.         |
  692.         ;
  693. Quiet        : tQUIET
  694.         { Options.quiet = TRUE; }
  695.         |
  696.         ;
  697. Aperture    : tAPERTURE Expr
  698.         {
  699.             Camera.aperture = $2;
  700.         }
  701.         ;
  702. Focaldist    : tFOCALDIST Expr
  703.         {
  704.             Camera.focaldist = $2;
  705.         }
  706.         ;
  707. Eyesep        : tEYESEP Expr
  708.         {
  709.             if (!Options.eyesep_set)
  710.                 Options.eyesep = $2;
  711.         }
  712.         ;
  713. Maxdepth    : tMAXDEPTH IExpr
  714.         {
  715.             if (!Options.maxdepth_set)
  716.                 Options.maxdepth = $2;
  717.         }
  718.         ;
  719. Background    : tBACKGROUND Color
  720.         {
  721.             Screen.background = $2;
  722.         }
  723.         ;
  724. Shadowtransp    : tSHADOWTRANSP
  725.         {
  726.             Options.shadowtransp = !Options.shadowtransp;
  727.         }
  728.         ;
  729. Light        : LightType
  730.         {
  731.             LightAddToDefined($1);
  732.         }
  733.         | LightType tNOSHADOW
  734.         {
  735.             $1->shadow = FALSE;
  736.             LightAddToDefined($1);
  737.         }
  738.         | tLIGHT Intensity tAMBIENT
  739.         {
  740.             Options.ambient = $2;
  741.         }
  742.         | Lightdef tAREA Vector Vector IExpr Vector IExpr
  743.         {
  744.             extern void AreaLightCreate();
  745.             /* Area light is strange in that the
  746.              * Creation routine does the installation.
  747.              */
  748.             AreaLightCreate(&$1, &$3, &$4, $5, &$6, $7, TRUE);
  749.         }
  750.         | Lightdef tAREA Vector Vector IExpr Vector IExpr tNOSHADOW
  751.         {
  752.             extern void AreaLightCreate();
  753.             /* Area light is strange in that the
  754.              * Creation routine does the installation.
  755.              */
  756.             AreaLightCreate(&$1, &$3, &$4, $5, &$6, $7, FALSE);
  757.         };
  758. LightType    : Lightdef tPOINT Vector
  759.         {
  760.             $$ = LightPointCreate(&$1, &$3);
  761.         }
  762.         | Lightdef tDIRECTIONAL Vector
  763.         {
  764.             $$ = LightInfiniteCreate(&$1, &$3);
  765.         }
  766.         | Lightdef tEXTENDED Expr Vector
  767.         {
  768.             $$ = LightExtendedCreate(&$1, $3, &$4);
  769.         }
  770.         | Lightdef tSPOT Vector Vector Expr
  771.         {
  772.             $$ = LightSpotCreate(&$1, &$3, &$4, $5, 0., 0.);
  773.         }
  774.         | Lightdef tSPOT Vector Vector Expr Expr Expr
  775.         {
  776.             /* light <intens> spot from <to> coef inner_rad
  777.                     outer_rad */
  778.             $$ = LightSpotCreate(&$1, &$3, &$4, $5, $6, $7);
  779.         };
  780. Lightdef    : tLIGHT Intensity
  781.         {
  782.             $$ = $2;
  783.         }
  784.         ;
  785. CurSurf        : tAPPLYSURF Surface
  786.         {
  787.             CurSurf->surf = $2;
  788.         }
  789.         ;
  790. OptSurface    : Surface
  791.         | /* EMPTY */
  792.         {
  793.             $$ = CurSurf->surf;
  794.         }
  795.         ;
  796. Surface        : NamedSurf
  797.         | ModifyNamedSurf
  798.         | SurfSpec
  799.         ;
  800. NamedSurf    : tSTRING
  801.         {
  802.             $$ = SurfaceGetNamed($1);
  803.             /*
  804.              * Free up memory allocated for surf name.
  805.              * We bother doing this because for large models
  806.              * converted from 3.0, surfnames this can account
  807.              * for lots o' bytes.
  808.              */
  809.             free((voidstar)$1);
  810.         }
  811.         | tCURSURF
  812.         {
  813.             extern Surface DefaultSurface;
  814.  
  815.             if (CurSurf->surf)
  816.                 $$ = CurSurf->surf;
  817.             else
  818.                 $$ = &DefaultSurface;
  819.         }
  820.         ;
  821. ModifyNamedSurf : CopyNamedSurf SurfComponent SurfComponents
  822.         {
  823.             $$ = tmpsurf;
  824.             tmpsurf = (Surface *)NULL;
  825.         }
  826.         | CopyCurSurf SurfComponent SurfComponents
  827.         {
  828.             $$ = tmpsurf;
  829.             tmpsurf = (Surface *)NULL;
  830.         }
  831.         ;
  832. CopyNamedSurf    : tSTRING
  833.         {
  834.             tmpsurf = SurfaceCopy(SurfaceGetNamed($1));
  835.         }
  836.         ;
  837. CopyCurSurf    : tCURSURF
  838.         {
  839.             extern Surface DefaultSurface;
  840.             if (CurSurf->surf)
  841.                 tmpsurf = SurfaceCopy(CurSurf->surf);
  842.             else
  843.                 tmpsurf = SurfaceCopy(&DefaultSurface);
  844.         }
  845.         ;
  846. SurfSpec    : SurfComponent SurfComponents
  847.         {
  848.             $$ = tmpsurf;
  849.             tmpsurf = (Surface *)NULL;
  850.         } 
  851.         ;
  852. SurfDef        : tSURFACE tSTRING Surface
  853.         {
  854.             tmpsurf = SurfaceCopy($3);
  855.             tmpsurf->name = strsave($2);
  856.             SurfaceAddToDefined(tmpsurf);
  857.             tmpsurf = (Surface *)NULL;
  858.         }
  859.         | tSURFACE tSTRING
  860.         {
  861.             /* black surface */
  862.             tmpsurf = SurfaceCreate();
  863.             tmpsurf->name = strsave($2);
  864.             SurfaceAddToDefined(tmpsurf);
  865.             tmpsurf = (Surface *)NULL;
  866.         }
  867.         ;
  868. SurfComponents    : SurfComponents SurfComponent
  869.         | /* EMPTY */
  870.         ;
  871. SurfComponent    : Ambient
  872.         | Diffuse
  873.         | Specular
  874.         | Specpow
  875.         | Body
  876.         | Reflect
  877.         | Transp
  878.         | Extinct
  879.         | Index
  880.         | Translu
  881.         | Noshadow
  882.         ;
  883. Ambient        : tAMBIENT Color
  884.         {
  885.             if (tmpsurf == (Surface *)NULL)
  886.                 tmpsurf = SurfaceCreate();
  887.             tmpsurf->amb = $2;
  888.         }
  889.         ;
  890. Diffuse        : tDIFFUSE Color
  891.         {
  892.             if (tmpsurf == (Surface *)NULL)
  893.                 tmpsurf = SurfaceCreate();
  894.             tmpsurf->diff = $2;
  895.         }
  896.         ;
  897. Specular    : tSPECULAR Color
  898.         {
  899.             if (tmpsurf == (Surface *)NULL)
  900.                 tmpsurf = SurfaceCreate();
  901.             tmpsurf->spec = $2;
  902.         }
  903.         ;
  904. Body        : tBODY Color
  905.         {
  906.             if (tmpsurf == (Surface *)NULL)
  907.                 tmpsurf = SurfaceCreate();
  908.             tmpsurf->body = $2;
  909.         };
  910. Extinct        : tEXTINCT Expr
  911.         {
  912.             if (tmpsurf == (Surface *)NULL)
  913.                 tmpsurf = SurfaceCreate();
  914.             tmpsurf->statten = $2;
  915.         };
  916. Specpow        : tSPECPOW Expr
  917.         {
  918.             if (tmpsurf == (Surface *)NULL)
  919.                 tmpsurf = SurfaceCreate();
  920.             tmpsurf->srexp = $2;
  921.         }
  922.         ;
  923. Reflect        : tREFLECT Expr
  924.         {
  925.             if (tmpsurf == (Surface *)NULL)
  926.                 tmpsurf = SurfaceCreate();
  927.             tmpsurf->reflect = $2;
  928.         }
  929.         ;
  930. Transp        : tTRANSP Expr
  931.         {
  932.             if (tmpsurf == (Surface *)NULL)
  933.                 tmpsurf = SurfaceCreate();
  934.             tmpsurf->transp = $2;
  935.         }
  936.         ;
  937. Index        : tINDEX Expr
  938.         {
  939.             if (tmpsurf == (Surface *)NULL)
  940.                 tmpsurf = SurfaceCreate();
  941.             tmpsurf->index = $2;
  942.         }
  943.         ;
  944. Translu        : tTRANSLU Expr Color Expr
  945.         {
  946.             if (tmpsurf == (Surface *)NULL)
  947.                 tmpsurf = SurfaceCreate();
  948.             tmpsurf->translucency = $2;
  949.             tmpsurf->translu = $3;
  950.             tmpsurf->stexp = $4;
  951.         }
  952.         ;
  953. Noshadow    : tNOSHADOW
  954.         {
  955.             if (tmpsurf == (Surface *)NULL)
  956.                 tmpsurf = SurfaceCreate();
  957.             tmpsurf->noshadow = TRUE;
  958.         }
  959.         ;
  960. HeightField    : tHEIGHTFIELD Surface Filename
  961.         {
  962.             $$ = GeomHfCreate($3);
  963.             if ($$)
  964.                 $$->surf = $2;
  965.         }
  966.         | tHEIGHTFIELD Filename
  967.         {
  968.             $$ = GeomHfCreate($2);
  969.         }
  970.         ;
  971. Poly        : tPOLY OptSurface Polypoints
  972.         {
  973.             $$ = GeomPolygonCreate(Polypoints, Npoints,
  974.                 Options.flipnorm);
  975.             if ($$)
  976.                 $$->surf = $2;
  977.             Polypoints = (PointList *)NULL;
  978.             Npoints = 0;
  979.         }
  980.         ;
  981. Polypoints    : /* empty */
  982.         | Polypoints Polypoint
  983.         ;
  984. Polypoint    : Vector
  985.         {
  986.             PointList *ptmp;
  987.  
  988.             ptmp = (PointList *)Malloc(sizeof(PointList));
  989.             ptmp->vec = $1;
  990.             ptmp->next = Polypoints;
  991.             Polypoints = ptmp;
  992.             Npoints++;
  993.         }
  994.         ;
  995. Aggregate    : AggregateDef
  996.         {
  997.             if (Defstack->obj) {
  998.                 /*
  999.                  * Set object texture to current texture.
  1000.                  */
  1001.                 Defstack->obj->texture = CurText;
  1002.             }
  1003.             CurText = (Texture *)NULL;
  1004.             /*
  1005.              * Pop topmost object on stack.
  1006.              */
  1007.             $$ = Defstack->obj;
  1008.             Defstack = GeomStackPop(Defstack);
  1009.             /* Pop current surface */
  1010.             CurSurf = SurfPop(CurSurf);
  1011.             /* Make current default surf aggregate's default */
  1012.             $$->surf = CurSurf->surf;
  1013.         }
  1014.         ;
  1015. AggregateDef    : AggregateCreate Aggdefs tEND
  1016.         {
  1017.             /* Convert aggregate, pop stacks, etc. */
  1018.             if ($1) {
  1019.                 if (Defstack->obj->next == (Geom *)NULL) {
  1020.                     RLerror(RL_WARN,
  1021.                         "Null object defined.\n");
  1022.                     Defstack->obj = (Geom *)NULL;
  1023.                 } else {
  1024.                     /*
  1025.                      * Convert the linked list of objects
  1026.                      * associated with the topmost object
  1027.                      * to the appropriate aggregate type.
  1028.                      */
  1029.                     Defstack->obj->prims=AggregateConvert(
  1030.                         Defstack->obj,
  1031.                         Defstack->obj->next);
  1032.                     /*
  1033.                      * Make sure conversion worked OK.
  1034.                      */
  1035.                     if (Defstack->obj->prims <= 0)
  1036.                         Defstack->obj = (Geom *)NULL;
  1037.                 }
  1038.             }
  1039.         }
  1040.         ;
  1041. AggregateCreate    : AggregateType
  1042.         {
  1043.             if ($1) {
  1044.                 Defstack = GeomStackPush($1, Defstack);
  1045.                 CurSurf = SurfPush((Surface *)NULL, CurSurf);
  1046.             }
  1047.         };
  1048. AggregateType    : List
  1049.         | Grid
  1050.         | Csg
  1051.         ;
  1052. List        : tLIST
  1053.         {
  1054.             $$ = GeomListCreate();
  1055.         }
  1056.         ;
  1057. Grid        : tGRID IExpr IExpr IExpr
  1058.         {
  1059.             $$ = GeomGridCreate($2, $3, $4);
  1060.         }
  1061.         ;
  1062. Csg        : CombineOp
  1063.         {
  1064.             $$ = GeomCsgCreate($1);
  1065.             Options.csg = TRUE;
  1066.         }
  1067.         ;
  1068. CombineOp    : tUNION
  1069.         {
  1070.             $$ = CSG_UNION;
  1071.         }
  1072.         | tINTERSECT
  1073.         {
  1074.             $$ = CSG_INTERSECT;
  1075.         }
  1076.         | tDIFFERENCE
  1077.         {
  1078.             $$ = CSG_DIFFERENCE;
  1079.         }
  1080.             ;
  1081. Cone        : tCONE OptSurface Expr Vector Expr Vector
  1082.         {
  1083.             if (equal($3, $5)) {
  1084.                 /* It's really a cylinder */
  1085.                 $$ = GeomCylinderCreate($3, &$4, &$6);
  1086.             } else
  1087.                 $$ = GeomConeCreate($3, &$4, $5, &$6);
  1088.             if ($$)
  1089.                 $$->surf = $2;
  1090.         }
  1091.         ;
  1092. Cylinder    : tCYL OptSurface Expr Vector Vector
  1093.         {
  1094.             $$ = GeomCylinderCreate($3, &$4, &$5);
  1095.             if ($$)
  1096.                 $$->surf = $2;
  1097.         }
  1098.         ;
  1099. Sphere        : tSPHERE OptSurface Expr Vector
  1100.         {
  1101.             $$ = GeomSphereCreate($3, &($4));
  1102.             if ($$)
  1103.                 $$->surf = $2;
  1104.         }
  1105.         ;
  1106. Disc        : tDISC OptSurface Expr Vector Vector
  1107.         {
  1108.             $$ = GeomDiscCreate($3, &($4), &($5));
  1109.             if ($$)
  1110.                 $$->surf = $2;
  1111.         }
  1112.         ;
  1113. Box        : tBOX OptSurface Vector Vector
  1114.         {
  1115.             $$ = GeomBoxCreate(&$3, &$4);
  1116.             if ($$)
  1117.                 $$->surf = $2;
  1118.         }
  1119.         ;
  1120. Triangle    : tTRIANGLE OptSurface Vector Vector Vector
  1121.         {
  1122.             $$ = GeomTriangleCreate(FLATTRI, &($3), &($4), &($5),
  1123.                 (Vector *)NULL, (Vector *)NULL, (Vector *)NULL,
  1124.                 (Vec2d *)NULL, (Vec2d *)NULL, (Vec2d *)NULL,
  1125.                 Options.flipnorm);
  1126.             if ($$)
  1127.                 $$->surf = $2;
  1128.         }
  1129.         | tTRIANGLE OptSurface  Vector Vector
  1130.                     Vector Vector
  1131.                     Vector Vector
  1132.         {
  1133.             $$ = GeomTriangleCreate(PHONGTRI, &($3), &($5),
  1134.                 &($7), &($4), &($6), &($8),
  1135.                 (Vec2d *)NULL, (Vec2d *)NULL, (Vec2d *)NULL,
  1136.                 Options.flipnorm);
  1137.             if ($$)
  1138.                 $$->surf = $2;
  1139.         }
  1140.         | tTRIANGLEUV OptSurface Vector Vector Vec2d
  1141.                      Vector Vector Vec2d
  1142.                      Vector Vector Vec2d
  1143.         {
  1144.             $$ = GeomTriangleCreate(PHONGTRI, &($3), &($6), &($9),
  1145.                         &($4), &($7), &($10),
  1146.                         &($5), &($8), &($11),
  1147.                         Options.flipnorm);
  1148.             if ($$)
  1149.                 $$->surf = $2;
  1150.         }
  1151.         ;
  1152. Plane        : tPLANE OptSurface Vector Vector
  1153.         {
  1154.             $$ = GeomPlaneCreate(&($3), &($4));
  1155.             if ($$)
  1156.                 $$->surf = $2;
  1157.         }
  1158.         ;
  1159. Torus        : tTORUS OptSurface Expr Expr Vector Vector
  1160.         {
  1161.             $$ = GeomTorusCreate($3, $4, &($5), &($6));
  1162.             if ($$)
  1163.                 $$->surf = $2;
  1164.         }
  1165.         ;
  1166. Blob        : tBLOB OptSurface Expr MetaPoints
  1167.         {
  1168.             $$ = GeomBlobCreate($3, Metapoints, Npoints);
  1169.             if ($$)
  1170.                 $$->surf = $2;
  1171.             Metapoints = (MetaList *)NULL;
  1172.             Npoints = 0;
  1173.         }
  1174.         ;
  1175. MetaPoints    : /* empty */
  1176.         | MetaPoints MetaPoint
  1177.         ;
  1178. MetaPoint    : Expr Expr Expr Expr Expr
  1179.         {
  1180.             Metapoint = (MetaList *)Malloc(sizeof(MetaList));
  1181.             Metapoint->mvec.c0 = $1;
  1182.             Metapoint->mvec.rs = $2;
  1183.             Metapoint->mvec.x = $3;
  1184.             Metapoint->mvec.y = $4;
  1185.             Metapoint->mvec.z = $5;
  1186.             Metapoint->next = Metapoints;
  1187.             Metapoints = Metapoint;
  1188.             Npoints++;
  1189.         }
  1190.         ;
  1191. Outfile        : tOUTFILE Filename
  1192.         {
  1193.             if (Options.imgname != (char *)NULL)
  1194.                 /* Already set on command line. */
  1195.                 RLerror(RL_WARN,
  1196.                     "Ignoring output file name \"%s\".\n",
  1197.                     $2);
  1198.             else
  1199.                 Options.imgname = strsave($2);
  1200.         }
  1201.         ;
  1202. GlobalEffects    : tATMOSPHERE Effects
  1203.         {
  1204.             AtmosEffects = CurEffect;
  1205.             CurEffect = (Atmosphere *)NULL;
  1206.         }
  1207.         | tATMOSPHERE IExpr Effects
  1208.         {
  1209.             if ($2 <= 0.)
  1210.                 RLerror(RL_PANIC,
  1211.                 "Index of refraction must be positive.\n");
  1212.             TopMedium.index = $2;
  1213.             AtmosEffects = CurEffect;
  1214.             CurEffect = (Atmosphere *)NULL;
  1215.         }
  1216.         ;
  1217. Effects        : Effects Effect
  1218.         |
  1219.         ;
  1220. Effect        : EffectType
  1221.         {
  1222.             $1->next = CurEffect;
  1223.             CurEffect = $1;
  1224.         }
  1225.         ;
  1226. EffectType    : tMIST Color Color Expr Expr
  1227.         {
  1228.             $$ = AtmosMistCreate(&($2), &($3), $4, $5);
  1229.         }
  1230.         | tFOG Color Color
  1231.         {
  1232.             $$ = AtmosFogCreate(&($2), &($3));
  1233.         }
  1234.         | tFOGDECK Expr Expr Vector Expr IExpr Color Color
  1235.         {
  1236.             $$ = AtmosFogdeckCreate($2, $3, &$4, $5, $6, &$7, &$8);
  1237.         }
  1238.         ;
  1239. Color        : Expr Expr Expr
  1240.         {
  1241.             $$.r = $1;
  1242.             $$.g = $2;
  1243.             $$.b = $3;
  1244.         }
  1245.         ;
  1246. Vector        : Expr Expr Expr
  1247.         {
  1248.             $$.x = $1;
  1249.             $$.y = $2;
  1250.             $$.z = $3;
  1251.         }
  1252.         ;
  1253. Vec2d        : Expr Expr 
  1254.         {
  1255.             $$.u = $1;
  1256.             $$.v = $2;
  1257.         }
  1258.         ;
  1259. OptMapping    : Mapping
  1260.         | /* EMPTY */
  1261.         {
  1262.             $$ = UVMappingCreate();
  1263.         }
  1264.         ;
  1265. Mapping        : tMAP MapMethod
  1266.         {
  1267.             $$ = $2;
  1268.         }
  1269.         ;
  1270. MapMethod    : tUV
  1271.         {
  1272.             $$ = UVMappingCreate();
  1273.         }
  1274.         | tSPHERICAL
  1275.         {
  1276.             $$ = SphereMappingCreate((Vector *)NULL,
  1277.                 (Vector *)NULL, (Vector *)NULL);
  1278.         }
  1279.         | tSPHERICAL Vector Vector Vector
  1280.         {
  1281.             /* origin up uaxis */
  1282.             $$ = SphereMappingCreate(&$2, &$3, &$4);
  1283.         }
  1284.         | tCYLINDRICAL
  1285.         {
  1286.             $$ = CylMappingCreate((Vector *)NULL,
  1287.                 (Vector *)NULL, (Vector *)NULL);
  1288.         }
  1289.         | tCYLINDRICAL Vector Vector Vector
  1290.         {
  1291.             /* origin up uaxis */
  1292.             $$ = CylMappingCreate(&$2, &$3, &$4);
  1293.         }
  1294.         | tPLANAR
  1295.         {
  1296.             $$ = LinearMappingCreate((Vector *)NULL,
  1297.                 (Vector *)NULL, (Vector *)NULL);
  1298.         }
  1299.         | tPLANAR Vector Vector Vector
  1300.         {
  1301.             /* origin up uaxis */
  1302.             $$ = LinearMappingCreate(&$2, &$3, &$4);
  1303.         }
  1304.         ;
  1305. SurfCompName    : tAMBIENT
  1306.         {
  1307.             $$ = AMBIENT;
  1308.         }
  1309.         | tDIFFUSE
  1310.         {
  1311.             $$ = DIFFUSE;
  1312.         }
  1313.         | tBODY
  1314.         {
  1315.             $$ = BODY;
  1316.         }
  1317.         | tSPECULAR
  1318.         {
  1319.             $$ = SPECULAR;
  1320.         }
  1321.         | tREFLECT
  1322.         {
  1323.             $$ = REFLECT;
  1324.         }
  1325.         | tTRANSP
  1326.         {
  1327.             $$ = TRANSP;
  1328.         }
  1329.         | tSPECPOW
  1330.         {
  1331.             $$ = SPECPOW;
  1332.         }
  1333.         | tBUMP
  1334.         {
  1335.             $$ = BUMP;
  1336.         }
  1337.         | tINDEX
  1338.         {
  1339.             $$ = INDEX;
  1340.         }
  1341.         ;
  1342. Intensity    : Expr
  1343.         { $$.r = $$.g = $$.b = $1; }
  1344.         | Color
  1345.         ;
  1346. Print        : tPRINT Expr
  1347.         {
  1348.             fprintf(stderr,"%f\n",$2);
  1349.         }
  1350. Define        : tDEFINE tSTRING AnimExpr
  1351.         {
  1352.             SymtabAddEntry($2, $3->type, $3, NULL, $3->timevary, 0);
  1353.         };
  1354. IExpr        : Expr
  1355.         { $$ = (int)$1; }
  1356.         ;
  1357. Expr        : Float
  1358.         | ParenExpr
  1359.         {
  1360.             if (!$1->timevary) {
  1361.                 $$ = ExprEval($1);
  1362.             } else {
  1363.                 RLerror(RL_PANIC, "Illegal expression use.\n");
  1364.             }
  1365.         }
  1366.         ;
  1367. AnimExpr    : Float
  1368.         {
  1369.             $$ = ExprReuseFloatCreate($1);
  1370.         }
  1371.         | ParenExpr
  1372.         ;
  1373. ParenExpr    : '(' MExpr ')'
  1374.         {
  1375.             $$ = $2;
  1376.         };
  1377. MExpr        : tFLOAT
  1378.         {
  1379.             $$ = ExprFloatCreate($1, FALSE);
  1380.         }
  1381.         | tSTRING
  1382.         {
  1383.             $$ = ExprFloatSymtabFind($1);
  1384.         }
  1385.         | Symtabent '(' MExpr ')'
  1386.         {
  1387.             $$ = ExprResolve1($3, $1->value.fp, $1->timevary);
  1388.         }
  1389.         | Symtabent '(' MExpr ',' MExpr ')'
  1390.         {
  1391.             $$ = ExprResolve2($3, $5,
  1392.                     $1->value.fp,
  1393.                     $1->timevary);
  1394.         }
  1395.         | Symtabent '(' MExpr ',' MExpr ',' MExpr ')'
  1396.         {
  1397.             $$ = ExprResolve3($3, $5, $7, 
  1398.                     $1->value.fp,
  1399.                     $1->timevary);
  1400.         }
  1401.         | Symtabent '(' MExpr ',' MExpr ',' MExpr ',' MExpr ')'
  1402.         {
  1403.             $$ = ExprResolve4($3, $5, $7, $9, 
  1404.                     $1->value.fp,
  1405.                     $1->timevary);
  1406.         }
  1407.         | Symtabent
  1408.             '(' MExpr ',' MExpr ',' MExpr ',' MExpr ',' MExpr ')'
  1409.         {
  1410.             $$ = ExprResolve5($3, $5, $7, $9, $11,
  1411.                     $1->value.fp,
  1412.                     $1->timevary);
  1413.         }
  1414.         | '(' MExpr ')'
  1415.         {
  1416.             $$ = $2;
  1417.         }
  1418.         | MExpr '+' MExpr
  1419.         {
  1420.             $$ = ExprResolve2($1, $3, SumExpr, FALSE);
  1421.         }
  1422.         | MExpr '-' MExpr
  1423.         {
  1424.             $$ = ExprResolve2($1, $3, DiffExpr, FALSE);
  1425.         }
  1426.         | MExpr '*' MExpr
  1427.         {
  1428.             $$ = ExprResolve2($1, $3, MultExpr, FALSE);
  1429.         }
  1430.         | MExpr '/' MExpr
  1431.         {
  1432.             $$ = ExprResolve2($1, $3, DivideExpr, FALSE);
  1433.         }
  1434.         | MExpr '%' MExpr
  1435.         {
  1436.             $$ = ExprResolve2($1, $3, ModExpr, FALSE);
  1437.         }
  1438.         | '-' MExpr %prec UMINUS
  1439.         {
  1440.             $$ = ExprResolve1($2, NegateExpr, FALSE);
  1441.         }
  1442.         | '+' MExpr %prec UMINUS
  1443.         {
  1444.             $$ = $2;
  1445.         }
  1446.         | MExpr '^' MExpr
  1447.         {
  1448.             $$ = ExprResolve2($1, $3, pow, FALSE);
  1449.         } ;
  1450. Float        : tFLOAT
  1451.         | '-' tFLOAT
  1452.         { $$ = -$2; }
  1453.         | '+' tFLOAT
  1454.         { $$ = $2; };
  1455. Filename    : tSTRING
  1456.         | tFILENAME
  1457.         ;
  1458. Symtabent    : tSTRING
  1459.         {
  1460.             $$ = SymtabBuiltinFind($1);
  1461.         };
  1462. %%
  1463. /*
  1464.  * Issue error message containing filename and line number, and exit.
  1465.  */
  1466. /*VARARGS1*/
  1467. yyerror(s, pat1, pat2)
  1468. char *s, *pat1, *pat2;
  1469. {
  1470.     fprintf(stderr,"%s: Error: %s: line %d: ", Options.progname,
  1471.             yyfilename, yylineno);
  1472.     fprintf(stderr, s, pat1, pat2);
  1473.     if (*s && s[strlen(s) -1] != '\n')
  1474.         /* YACC doesn't put newlines on error messages. */
  1475.         fprintf(stderr,"\n");    
  1476.     fflush(stderr);
  1477.     exit(1);
  1478. }
  1479.  
  1480. Geom *
  1481. NewAggregate(obj)
  1482. Geom *obj;
  1483. {
  1484.     obj->name = Defstack->obj->name;
  1485.     obj->next = Defstack->obj->next;
  1486.     return obj;
  1487. }
  1488.